/-app
/-files ...
FileTree.ts
SyncStorageAccess.ts
/-imports
/-storage
/-typings
codemirror.d.ts
websql.d.ts
functions.ts
index.html
try.js
xxxxxxxxxx
1
module teapo.files {
2
  
3
  export class FileTree {
4
    
5
    private _ul: HTMLUListElement;
6
    private _rootNode: Node[];
7
​
8
    access: SyncStorageAccess;
9
​
10
    constructor(private _host: HTMLUListElement) {
11
      this._ul = getChildUL(this._host);
12
      // TODO: do something if ul is null
13
​
14
      this.access = {
15
        update: (byFullPath, timestamp) => this._update,
16
        read: (fullPaths) => this._read(fullPaths)
17
      };
18
    }
19
​
20
    private _update(
21
      byFullPath: storage.PropertiesByFullPath,
22
      timestamp: number): void { 
23
    }
24
​
25
    private _read(
26
      fullPaths: string[]): storage.PropertiesByFullPath {
27
      return {};
28
    }
29
​
30
    
31
    
32
  }
33
  
34
  class Node {
35
    
36
    name: string;
37
    fullPath: string;
38
​
39
    private _resolvedUL = false;
40
    private _ul: HTMLUListElement;
41
    private _children: Node[];
42
    private _li: HTMLLIElement;
43
​
44
    constructor(
45
      parentPath: string,
46
      li: HTMLLIElement);
47
    constructor(ul: HTMLUListElement);
48
    constructor (arg1, arg2) {
49
    
50
      if (arg2) {
51
​
52
                              this._li = li;
53
                              var liText = getLIText(this._li);
54
                              var slashPos = liText.indexOf('/');
55
                              if (slashPos >= 0)
56
                                      this._handleComplexPathOnLoad(liText);
57
      
58
                              this.name = liText;
59
                              this.fullPath = parentPath + '/' + liText;
60
    
61
                              this._ul = null;
62
                              this._children = null;
63
                            }
64
      else { 
65
​
66
                      this.name = '';
67
                      this.fullPath = '';
68
                      this._ul = ul;
69
                      this._li = null;
70
      
71
                      }
72
    }
73
​
74
    getNode(path: string, createIfAbsent: boolean): Node {
75
​
76
      this._ensureULResolved();
77
​
78
      if (!this._ul)
79
        throw new Error('Node is not a directory.');
80
      
81
      var name: string, restPath: string;
82
      
83
      var slashPos = path.indexOf('/');
84
      while (!slashPos) { // slight normalization, keep it for the sake of root paths
85
          path = path.slice(1);
86
          slashPos = path.indexOf('/');
87
      }
88
​
89
      if (slashPos < 0) {
71:5